package com.itheima.upload.controller;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("upload")
public class UploadController {

    //声明kua跨服务器上传的地址
    private String picPath = "http://127.0.0.1:9090/uploads/";

    @RequestMapping("pic")
    public String pic(MultipartFile uploadFile) throws IOException {
        //创建文件名
        String picName = UUID.randomUUID().toString() + ".jpg";

        //执行上传
        Client client = Client.create();
        WebResource webResource = client.resource(picPath + picName);
        webResource.put(uploadFile.getBytes());

        //返回成功页
        return "success";
    }
}
